<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="pageContent">
	<form method="post" id="goods_spec_main_form" action="${rootUrl}/goods/goods-spec<c:if test="${goodsSpec.id != 0 && goodsSpec.id != '' }">/${goodsSpec.id}</c:if>" class="pageForm required-validate" onsubmit="return beforeSubmit(this);">
		<c:if test="${goodsSpec.id != 0 && goodsSpec.id != '' }"><input type="hidden" name="_method" value="put"></c:if>
		<input type="hidden" id="spec_goodsSpecId" name="goodsSpec.id" value="${goodsSpec.id }">
		<input type="hidden" id="spec_goodsId" name="goodsSpec.goods.id" value="${goodsSpec.goods.id }">
		<div class="pageFormContent" layoutH="56">
			<p>
				<label>规格名：</label>
				<input type="hidden" id="goodsSpec_specId" name="goodsSpec.specId" value="${goodsSpec.specClass.id }">
				<input type="text" readonly="readonly" id="specName" name="goodsSpec.specClassName" class="required" size="30" value="${goodsSpec.specClass.name }" />
				<a class="btnLook" href="${rootUrl}/goods/spec-class/0/dialog" width="1200" height="720" lookupGroup="goodsSpec">规格</a>
			</p>
			<p>
				<label>规格编码：</label>
				<input type="text" readonly="readonly" id="specCode" name="goodsSpec.specClassCode" class="required" size="30" value="${goodsSpec.specClass.code }" />
			</p>
   		 </div>
    	<div class="formBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button id="theSubmit" onclick="dosub()" type="button">保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
    </form>
    	
</div>
<script>
	function dosub(){
		var preSpecId = "${goodsSpec.specClass.id }";
		var curSpecId = $("#goodsSpec_specId").val();
		var goodsId = $("#spec_goodsId").val();
		var goodsSpecId = $("#spec_goodsSpecId").val();
		var sid="";
		//var wstr = "该商品已存在sku<br>如果再添加规格的话，原来的sku商品将全部封存，商品将重新下架审核<br>确定继续吗？";
		var wstr = "该商品已存在sku<br>如果再添加规格的话，原来的sku商品需重新修改，商品将重新下架审核<br>确定继续吗？";
		//修改时
		if(goodsSpecId!="0" && preSpecId != curSpecId){
			sid = preSpecId;
			//wstr = "原来的规格已存在sku<br>如果再修改该规格的话，原来的sku商品将全部封存，商品将重新下架审核<br>确定继续吗？";
			wstr = "原来的规格已存在sku<br>如果再修改该规格的话，原来的sku商品需重新修改，商品将重新下架审核<br>确定继续吗？";
		}
		if(preSpecId == curSpecId){
			alert("规格没有变动，不能修改！");
		}else{
			$.ajax({
				url:"${rootUrl}/goods/goods-sku/0/getSkuBySpecNoMothBall",
				data:{specIdStr:sid,goodsId:goodsId},
				success:function(data){
					if(data == 0){
						$("#goods_spec_main_form").submit();
					}else{
						alertMsg.confirm(wstr, {
							okCall: function(){
								$("#goods_spec_main_form").submit();
							}
						});
					}
				}
			});
		}
	}
	function beforeSubmit(obj){
		$("#goodsSpec_specId").attr("name","goodsSpec.specClass.id");
		return validateCallback(obj, _afterAjaxDone);
	}
	function _afterAjaxDone(json){
		$("#goodsSpec_specId").attr("name","goodsSpec.specId");
		newDialogAjaxDone(json);
	}
</script>